<!-- 项目一览表 - 任务档案详情 -->
<template>
	<view>
		<view class="content" id="content">
			<view class="list_box" @touchstart="touchShow = false" @click="touchShow =false" @touchmove="touchShow = false">
				<template v-if="projectShowType != '1'">
					<view class="oyher_top">
						项目信息
					</view>
					<view class="basic_box">
						<view class="label">
							<view class="label_title">项目名称</view>
							<view class="label_info">{{ projectModel.projectName }}</view>
						</view>
						<view class="label">
							<view class="label_title">项目编号</view>
							<view class="label_info">{{ projectModel.finalNo }}</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">项目承接人</view>
								<view class="label_info">{{projectModel.undertaker_dictText}}</view>
							</view>
							<view class="label">
								<view class="label_title">项目来源</view>
								<view class="label_info">{{projectModel.projectSource_dictText}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">经营团队</view>
							<view class="label_info">{{projectModel.teamName_dictText}}</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">立项日期</view>
								<view class="label_info">{{projectModel.projectEstablishDate}}</view>
							</view>
							<view class="label">
								<view class="label_title">业绩归属年度</view>
								<view class="label_info">{{projectModel.year_dictText}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">签订单位</view>
							<view class="label_info">{{projectModel.signUnit_dictText}}</view>
						</view>
						<view class="label">
							<view class="label_title">业主单位</view>
							<view class="label_info">{{projectModel.ownerUnit_dictText}}</view>
						</view>
						
						<view class="flex_box">
							<view class="label">
								<view class="label_title">联系人</view>
								<view class="label_info">{{projectModel.contacts_dictText}}</view>
							</view>
							<view class="label">
								<view class="label_title">联系方式</view>
								<view class="label_num">{{projectModel.contactTel}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">项目所在地址</view>
							<view class="label_info">{{projectModel.address}}</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">预计合同额(元)</view>
								<view class="label_info">{{projectModel.estimatedContractAmount}}</view>
							</view>
							<view class="label">
								<view class="label_title">预计合同额大写</view>
								<view class="label_info">{{projectModel.estimatedContractcapitalChineseAmount}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">立项事由及说明</view>
							<view class="label_info">{{projectModel.establishReason?projectModel.establishReason:'--'}}</view>
						</view>
						<view class="label">
							<view class="label_title">相关附件</view>
							<view class="label_info"><file-list :fileList="projectModel.attachment"></file-list></view>
						</view>
					</view>
					<view class="other_box"></view>
					<view class="oyher_top">
						任务信息
					</view>
					<view class="basic_box">
						<view class="label">
							<view class="label_title">档案编号</view>
							<view class="label_info">{{ model.billNo }}</view>
						</view>
						<view class="label">
							<view class="label_title">业务分类</view>
							<view class="label_info">{{ model.categoryName }}</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">合同占比(%)</view>
								<view class="label_info">{{model.contractRate}}</view>
							</view>
							<view class="label">
								<view class="label_title">合同分配额(元)</view>
								<view class="label_info">{{model.contractAmount}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">生产团队</view>
							<view class="label_info">{{model.productTeam_dictText}}</view>
						</view>
						<view class="label">
							<view class="label">
								<view class="label_title">任务类型</view>
								<!-- model.taskType_dictText -->
								<view class="label_info">{{filterMultiDictText(this.dictOptions['taskType_dictText'], model.taskType + '')}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">实施部门</view>
							<view class="label_info">{{model.executeDepart_dictText}}</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">部门负责人</view>
								<view class="label_info">{{model.deptLeadName}}</view>
							</view>
							<view class="label">
								<view class="label_title">项目负责人</view>
								<view class="label_info">{{model.projLeadName}}</view>
							</view>
						</view>
						<template v-if="model.taskType == 1 || model.taskType == 4">
							<view class="label" v-if="model.taskType == 1">
								<view class="label_title">审核工程师</view>
								<view class="label_info">{{filterMultiDictText(this.dictOptions['approvalEngineer_dictText'], model.approvalEngineer + '')}}</view>
							</view>
							<view class="flex_box">
								<view class="label">
									<view class="label_title">审批级别</view>
									<view class="label_info">{{model.approvalLevel_dictText}}</view>
								</view>
								<view class="label">
									<view class="label_title">审批系数</view>
									<view class="label_info">{{model.approvalCoefficient}}</view>
								</view>
							</view>
							<view class="flex_box">
								<view class="label">
									<view class="label_title">行业类别</view>
									<view class="label_info">{{model.industryCategory_dictText}}</view>
								</view>
								<view class="label">
									<view class="label_title">行业系数</view>
									<view class="label_info">{{model.industryCoefficient}}</view>
								</view>
							</view>
							<view class="flex_box">
								<view class="label">
									<view class="label_title">复杂程度</view>
									<view class="label_info">{{filterMultiDictText(this.dictOptions['complexity_dictText'], model.complexity + '')}}</view>
								</view>
								<view class="label">
									<view class="label_title">复杂系数</view>
									<view class="label_info">{{model.complexCoefficient}}</view>
								</view>
							</view>
						</template>
						<template v-if="model.taskType == 2">
							<view class="flex_box">
								<view class="label">
									<view class="label_title">是否出具报告</view>
									<view class="label_info">{{model.isOutReport_dictText}}</view>
								</view>
								<view class="label">
									<view class="label_title">费用核算方式</view>
									<view class="label_info">{{model.expenseAccountingMethod_dictText}}</view>
								</view>
							</view>
						</template>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">是否变更中</view>
								<view class="label_info">{{model.changeStatus_dictText}}</view>
							</view>
							<view class="label">
								<view class="label_title">任务状态</view>
								<view class="label_info">{{model.distributionType_dictText}}</view>
							</view>
						</view>
						
						<view class="label">
							<view class="label_title">说明</view>
							<view class="label_info">{{model.instruction?model.instruction:'--'}}</view>
						</view>
						<view class="label">
							<view class="label_title">任务附件</view>
							<view class="label_info"><file-list :fileList="model.taskFile"></file-list></view>
						</view>
					</view>
					<view class="other_box"></view>
					<view class="oyher_top">项目成员</view>
					<projectMemberListItem :dataSource="memberDataSource"></projectMemberListItem>
					
					<view class="other_box"></view>
					<view class="oyher_top">项目预算</view>
					<view class="basic_box">
						<view class="flex_box">
							<view class="label">
								<view class="label_title">预算总工时(人天)</view>
								<view class="label_info">{{model.expectWorkTime}}</view>
							</view>
							<view class="label">
								<view class="label_title">人工总成本(元)</view>
								<view class="label_info">{{model.workCost}}</view>
							</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">委外费(元)</view>
								<view class="label_info">{{model.outsourcingFee}}</view>
							</view>
							<view class="label">
								<view class="label_title">差旅费(元)</view>
								<view class="label_info">{{model.travelFee}}</view>
							</view>
						</view>
						<view class="flex_box">
							<view class="label">
								<view class="label_title">专家评审费(元)</view>
								<view class="label_info">{{model.professionReviewFee}}</view>
							</view>
							<view class="label">
								<view class="label_title">其他成本(元)</view>
								<view class="label_info">{{model.otherCost}}</view>
							</view>
						</view>
						<view class="label">
							<view class="label_title">项目预算合计(元)</view>
							<view class="label_info">{{model.totalProjectBudget?model.totalProjectBudget:'--'}}</view>
						</view>
					</view>
				</template>
				
				<template>
					<view class="other_box"></view>
					<view class="oyher_top">任务进度</view>
					<view class="basic_box">
						<view class="label">
							<view class="label_title">进度模板</view>
							<view class="label_info">{{model.templateName}}</view>
						</view>
					</view>
					<taskProgressTemplateListItem :dataSource="progressDataSource" v-if="progressDataSource && progressDataSource.length"></taskProgressTemplateListItem>
				</template>
				<template>
					<view class="other_box"></view>
					<view class="oyher_top">款项进度</view>
					<view class="basic_box">
						<view class="label">
							<view class="label_title">履约保证金(元)</view>
							<view class="label_info">{{model.bail !== null?model.bail:'--'}}</view>
						</view>
					</view>
					<moneyProgerssListItem :dataSource="moneyDataSource" @clickPayment="clickPayment"></moneyProgerssListItem>
				</template>
				<view class="other_box"></view>
				<u-sticky bgColor="#fff">
					<u-tabs 
					:list="listTab" 
					@click="clickTab"
					:current="tabCurrent"
					:activeStyle="{
						fontWeight: 500,
						color: '#171717'
					}"
					:inactiveStyle="{
						color:'#C6C6C6',
						fontWeight: 400
					}"
					lineColor="#1E6FFF"></u-tabs>
				</u-sticky>
				<template v-if="tabCurrent == 0">
					<view class="oyher_top">关联任务委托</view>
					<taskDistributionReportListItem :dataSource="taskDistributionDataSource" @click="handleTask"></taskDistributionReportListItem>
				</template>
				<template v-if="tabCurrent == 1">
					<view class="oyher_top">关联任务再委托</view>
					<taskReDistributionReportListItem :dataSource="taskReDistributionDataSource"></taskReDistributionReportListItem>
				</template>
				<template v-if="tabCurrent == 2">
					<view class="oyher_top">关联任务委托变更</view>
					<taskDistributionReportListItem :dataSource="taskDistributionChangeDataSource" @click="handleTask"></taskDistributionReportListItem>
				</template>
				<template v-if="tabCurrent == 3">
					<view class="oyher_top">关联报告审核</view>
					<reportAuditFormListItem :dataSource="reportAuditDataSource"></reportAuditFormListItem>
				</template>
			</view>
		</view>
	</view>
</template>
<script>
	import http from '@/utils/request/index.js'
	import specialHttp from '@/utils/request/specialIndex' // 特殊请求方式，直接返回res
	import address from '@/utils/address.js'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import projectMemberListItem from './components/projectMemberListItem' // 项目成员列表
	import taskProgressTemplateListItem from './components/taskProgressTemplateListItem' // 进度列表
	import moneyProgerssListItem from './components/moneyProgerssListItem' // 款项进度列表
	import taskDistributionReportListItem from './components/taskDistributionReportListItem' // 任务委托列表
	import taskReDistributionReportListItem from './components/taskReDistributionReportListItem' // 任务再委托列表
	import reportAuditFormListItem from './components/reportAuditFormListItem' // 报告审核
	import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
	export default {
		components: {fileList, projectMemberListItem, taskProgressTemplateListItem, moneyProgerssListItem, taskDistributionReportListItem, taskReDistributionReportListItem, reportAuditFormListItem},
		data() {
			return {
				filterMultiDictText,
				dictOptions: {},
				listTab: [
					{
						name: '关联任务委托'
					},
					{
						name: '关联任务再委托'
					},
					{
						name: '关联任务委托变更'
					},
					{
						name: '关联报告审核'
					},
				],
				tabCurrent: 0, // 默认第一个
				id: '', // 项目id 
				projectTaskId: '', // 任务详情id
				projectModel: {}, // 项目信息
				model: {},
				address,
				dataSource: [], // 任务信息
				progressDataSource: [], // 任务进度
				moneyDataSource: [], // 款项进度列表
				taskDistributionDataSource: [], // 任务委托列表
				taskDistributionChangeDataSource: [], // 任务委托变更列表
				taskReDistributionDataSource: [], // 任务再委托列表
				reportAuditDataSource: [], // 报告审核列表
				progressShowType: '-2', // 控制进度是否显示
				projectShowType: '-1', // 控制进度是否显示
				memberDataSource: [], // 项目成员列表
			}
		},
		async onLoad(options) {
			this.initDictConfig()
			this.id = await options.id || ''
			this.projectTaskId = await options.projectTaskId || ''
			if (options.projectTaskId) {
				this.getTaskDetail() // 任务详情信息
				this.getProjectTaskProgressList() // 进度信息
				this.getProjectMemberList() // 项目成员信息
				this.getMoneyProgressList() // 款项进度列表信息
			}
			if (options.id) {
				this.getDetail() // 项目信息
				this.getProjectTaskList() // 任务信息
				this.getQueryByEntity() // 获取履约保证金
			}
			if (options.id && options.projectTaskId) {
				this.getTaskDistributionList() // 任务委托
				this.getRsTaskDistributionList() // 任务再委托
				this.getTaskDistributionChangeList() // 任务委托变更
				this.getReportAuditList() // 报告审核
			}
		},
		methods: {
			async initDictConfig() {
				// 任务类型
			  initDictOptions('task_type').then((res) => {
			    if (res.success) {
			      this.$set(this.dictOptions, 'taskType_dictText', res.result)
			    }
			  })
				// 复杂程度
			  initDictOptions('industry_coefficient').then((res) => {
			    if (res.success) {
			      this.$set(this.dictOptions, 'complexity_dictText', res.result)
			    }
			  })
				// 人员姓名
			  initDictOptions('erp_employee_file,name,id').then((res) => {
			    if (res.success) {
			      this.$set(this.dictOptions, 'approvalEngineer_dictText', res.result)
			    }
			  })
			},
			// 获取任务详情信息
			async getTaskDetail () {
				http.get('/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList', { id: this.projectTaskId }).then(async (res) => {
				  if (res.success) {
				    this.model = (res.result.records && res.result.records.length) ? res.result.records[0] : {}
						// this.model.address = this.getAddress(res.result.areaCode) + res.result.projectAddress
				  }
				})
			},
			
			// 获取项目信息
			async getDetail () {
				http.get('/api/erp/omc/project/erpOmcProject/queryById', { id: this.id }).then(async (res) => {
				  if (res.success) {
						this.projectModel = res.result
						this.projectModel.address = this.getAddress(res.result.areaCode) + res.result.projectAddress
				  }
				})
			},
			// 获取任务信息
			async getProjectTaskList (){
				specialHttp.get('/api/erp/omc/project/erpOmcProjectTask/listById', { id: this.id }).then(async (res) => {
					if (res.length > 0) {
						this.dataSource = res || res.result;
					}
				})
			},
			// 获取项目成员
			async getProjectMemberList () {
				http.get('/api/erp/omc/project/erpOmcProjectTaskDt/list', { mainId: this.projectTaskId }).then(async (res) => {
				  if (res.success) {
						this.memberDataSource = res.result || []
				  }
				})
			},
			// 进度信息
			async getProjectTaskProgressList () {
				const params = await {
						projectId: this.id
					}
				http.get('/api/erp/omc/project/erpOmcProjectTaskFinal/queryTaskNodeList', {taskId: this.projectTaskId}).then(async res => {
					if (res.success) {
						this.progressDataSource = res.result || []
					} else {
						this.$message.warning(res.message)
					}
				})
			},
			// 款项进度列表
			async getMoneyProgressList () {
				const params = await {
					projectId: this.id
				}
				http.get('/api/erp/omc/project/erpOmcProjectTaskFinal/queryPaymentNodeList', {taskId: this.projectTaskId}).then(async res => {
					if (res.success) {
						this.moneyDataSource = res.result || []
					} else {
						this.$message.warning(res.message)
					}
				})
			},
			// 任务委托列表
			async getTaskDistributionList () {
				let params = await {
					projectId: this.id,
					taskId: this.projectTaskId,
					pageNo: 1,
					pageSize: 100,
					applyType: '1' // 任务委托
				};
				http.get('/api/erp/omc/task/erpOmcTaskDistribution/allList', params).then(async res => {
					if (res.success) {
						this.taskDistributionDataSource = res.result.records || []
					} else {
						this.$message.warning(res.message)
					}
				})
			},
			// 任务委托变更列表
			async getTaskDistributionChangeList () {
				let params = await {
					projectId: this.id,
					taskId: this.projectTaskId,
					pageNo: 1,
					pageSize: 100,
					column: 'createTime',
					order: 'desc',
					applyType: '2' // 任务委托变更
				};
				http.get('/api/erp/omc/task/erpOmcTaskDistribution/allList', params).then(async res => {
					if (res.success) {
						this.taskDistributionChangeDataSource = res.result.records || []
					} else {
						this.$message.warning(res.message)
					}
				})
			},
			// 任务再委托列表
			async getRsTaskDistributionList () {
				let params = await {
					projectId: this.id,
					taskId: this.projectTaskId,
					pageNo: 1,
					pageSize: 100,
					column: 'createTime',
					order: 'desc',
				};
				http.get('/api/erp/task/erpOmcTaskRedistribution/allList', params).then(async res => {
					if (res.success) {
						this.taskReDistributionDataSource = res.result.records || []
					} else {
						this.$message.warning(res.message)
					}
				})
			},
			// 报告审核
			async getReportAuditList () {
				let params = await {
					projectId: this.id,
					taskId: this.projectTaskId,
					pageNo: 1,
					pageSize: 100,
					column: 'createTime',
					order: 'desc',
				};
				http.get('/api/erp/omc/reportaudit/erpReportAudit/allLists', params).then(async res => {
					if (res.success) {
						this.reportAuditDataSource = res.result.records || []
					} else {
						this.$message.warning(res.message)
					}
				})
			},
			// 获取履约保证金
			async getQueryByEntity (){
				var params = {
					preProjectId: this.id,
					feeCategory: '2',
					bpmStatus: '3'
				}
				specialHttp.get('/api/erp/finance/deposit/erpFinanceProjectDepositBill/queryByEntity', params).then(async (res) => {
					 if (res.success) {
						let data = res.result
						this.$set(this.model, 'bail', data.remittanceAmount)
					} else {
						this.$set(this.model, 'bail', null)
					}
				})
			},
			// 地址显示
			getAddress(areaCode) {
			  var arr = areaCode.split(',')
			  var addressDetail = ''
			  this.address.map((value) => {
			    if (arr[0] && value.code == arr[0]) {
			      addressDetail = value.name
			      value.children.map((val) => {
			        if (arr[1] && val.code == arr[1]) {
			          addressDetail = addressDetail + val.name
			          val.children.map((item) => {
			            if (arr[2] && item.code == arr[2]) {
			              addressDetail = addressDetail + item.name
			            }
			          })
			        }
			      })
			    }
			  })
			  return addressDetail
			},
			// 点击款项进度中的查看关联收款单
			clickPayment(record) {
				uni.navigateTo({
					url:`/pages/common/ErpAssociatedReceiptList?id=${record.id}`
				})
			},
			
			// 点击任务委托,任务委托变更编号
			handleTask (record) {
				uni.navigateTo({
					url:`/pages/reportFilesList/ErpOmcTaskDistributionForm?id=${record.id}&applyType=${record.applyType}`
				})
			},
			
			clickTab (value) {
				if (value.index != this.tabCurrent) {
					if (value.index == 0) {
						this.getTaskDistributionList() // 任务委托
					} else if (value.index == 1) {
						this.getRsTaskDistributionList() // 任务再委托
					} else if (value.index == 2) {
						this.getTaskDistributionChangeList() // 任务委托变更
					} else {
						this.getReportAuditList() // 报告审核
					}
				}
				this.tabCurrent = value.index
			}
		}
	}
</script>
<style lang="less" scoped>
	.address_text {
		color: #1E6FFF !important;
	}
	.no_address {
		line-height: 36rpx;
		color: #171717;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	.file_images{
		display: flex;
		flex-wrap: wrap;
		margin-top: 16rpx;
		.file_image{
			width: 190rpx;
			height:190rpx;
			background: rgba(0,0,0,0.02);
			border-radius: 10rpx;
			border: 1px solid rgba(0,0,0,0.08);
			margin-right: 24rpx;
			position: relative;
			padding: 2rpx;
			.file_image_img{
				width: 100%;
				height: 100%;
			}
			.file_image_open{
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%,-50%);
			}
		}
	}
	.top_bottom{
		border-top: 1px solid #f2f2f2;
	}
	.top_bor{
		border-top: 1px solid #f2f2f2;
		border-bottom: none !important;
	}
	.no_bor {
		margin-top: 0 !important;

		// .oyher_top {
		// 	border-bottom: none;
		// }
	}

	.saoma {
		color: #FFFFFF;
		font-size: 16px;
		font-weight: 400;
		padding-right: 32rpx;
		line-height: 44rpx;
	}
	
	.content {
		width: 100%;
		// height: auto;
	}

	.detail_tip {
		padding: 40rpx 20rpx 20rpx;
		box-sizing: border-box;
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #7F7F7F;
	}

	.type_box {
		display: flex;
		flex-wrap: wrap;

		.type_info {
			width: 120rpx;
			height: 64rpx;
			background: #F7F7F7;
			border-radius: 4px;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 14px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #7F7F7F;
			margin-right: 16rpx;
			margin-bottom: 16rpx;
		}
	}

	.bot_botm {
		margin-bottom: 20rpx;

		.label {
			margin-bottom: 0 !important;
		}
	}

	.bor-bot-no {
		padding-bottom: 20rpx;
		box-sizing: border-box;
		margin-bottom: 0 !important;
		border-bottom: 1px solid #f2f2f2;
	}

	// 下面的线
	.bor-bot {
		padding-bottom: 32rpx;
		box-sizing: border-box;
		border-bottom: 1px solid #f2f2f2;
	}

	.other_box {
		margin-top: 20rpx;
	}

	.oyher_top {
		padding: 16rpx 36rpx 16rpx 44rpx;
		box-sizing: border-box;
		border-bottom: 1px solid #F2F2F2;
		background-color: #FFFFFF;
		position: relative;
		font-size: 16px;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;

		&::before {
			content: ''; // 必须
			position: absolute;
			left: 32rpx;
			top: 50%;
			transform: translate(0, -50%);
			width: 6rpx;
			height: 29rpx;
			background-color: #1e6fff;
		}
	}

	.basic_box {
		padding: 20rpx 32rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}
	
	.label {
		margin-bottom: 20rpx;
		flex: 1;
	}
	
	.label_image{
		width: 320rpx;
		height: 180rpx;
		border-radius: 10rpx;
	}
	
	.label_title {
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #B2B2B2;
		height: 20px;
		margin-right: 16rpx;
	}

	.label_info {
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #171717;
	}

	.label_num {
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #1E6FFF;
	}

	.flex_box {
		display: flex;
		// align-items: center;
	}
	
</style>
